{include file="public/header"}

<body>
  <div class="layui-fluid">
    <div class="layui-row">
      <form action="" method="post" class="layui-form layui-form-pane">
    <div class="layui-card layui-form" lay-filter="component-form-element">
          <div class="layui-card-header">姓名</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <input
                type="text"
                id="title"
                name="name"
                value="{$row.name|default=''}"
                required=""
                lay-verify="required"
                autocomplete="off"
                class="layui-input"
              />
            </div>
          </div>
        </div>
        <div class="layui-card layui-form" lay-filter="component-form-element">
          <div class="layui-card-header">账号</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <input
                type="text" 
                name="account"
                value="{$row.account|default=''}"
                required=""
                lay-verify="required"
                autocomplete="off"
                class="layui-input"
              />
            </div>
          </div>
        </div>
        <div class="layui-card layui-form" lay-filter="component-form-element">
          <div class="layui-card-header">类型</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
                <select name="type" lay-verify="" lay-filter="type">
                    <option value="0">选择类型</option>
                    {foreach :config('config.typepeople') as $k =>  $v}
                        <option value="{$k}" {if !empty($row.type) && $row.type==$k}selected{/if}> {$v|default=''}</option>
                    {/foreach}
                </select>
            </div>
          </div>
        </div>
        <div class="layui-card layui-form" lay-filter="component-form-element">
          <div class="layui-card-header">负责项目</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
                <input type="radio" lay-filter="ptype" name="ptype" value="1" title="全部项目(以后新增项目自动有权限)" {if empty($row.project) || $row.project==0}checked{/if}>
                <input type="radio" lay-filter="ptype" name="ptype" value="2" title="选择项目" {if !empty($row.project)}checked{/if}>
            </div>
          </div>
        </div>
        <div class="layui-card layui-form" id="shows" {if empty($row.project) || $row.project==0}style="display:none"{/if}>
          <div class="layui-card-header">选择项目</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
                {foreach :config('config.type') as $k =>  $v}
                {if $k != 1}
                 <input type="checkbox" name="project[]" title="{$v}" value="{$k}" lay-skin="primary" {if !empty($row.project) && in_array($k,$row.project)}checked{/if}>
                 {/if}
                {/foreach}
            </div>
          </div>
        </div>
        <div class="layui-card layui-form" lay-filter="component-form-element">
          <div class="layui-card-header">
            账号密码(新账号必须填写，老账号填写进行修改)
          </div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <input
                type="password"
                id="title"
                name="password"
                autocomplete="off"
                class="layui-input"
              />
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <input type="hidden" value="{$row['id']|default='0'}" name="id" />
          <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
        </div>
      </form>
    </div>
  </div>
  {include file="public/footer"}
  <script>
    layui.use(["form", "layer", "upload"], function () {
      $ = layui.jquery;
      var form = layui.form,
        upload = layui.upload,
        element = layui.element,
        layer = layui.layer;
        form.on('radio(ptype)', function(data){
  if(data.value == 2){
      $('#shows').show();
  }else{
      $('#shows').hide();
  }
});
      //监听提交
      form.on("submit(add)", function (data) {
        //发异步，把数据提交给php
        $.ajax({
          type: "post",
          data: data.field,
          success: function (res) {
            if (res.status == 0) {
              layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                parent.location.reload();
                parent.layer.close(index);
              });
            } else {
              layer.msg(res.msg, { icon: 2, time: 1000 });
            }
          },
        });
        return false;
      });
    });
  </script>
</body>
